package org.jeecg.modules.wlhy.bill.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.wlhy.bill.entity.HyCarrierBill;
import org.jeecg.modules.wlhy.bill.entity.HyDriverBill;
import org.jeecg.modules.wlhy.bill.service.IHyDriverBillService;
import org.jeecg.modules.wlhy.setting.service.IHySettingService;
import org.jeecg.modules.wlhy.utils.DataMaskingUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

 /**
 * @Description: hy_driver_bill
 * @Author: jeecg-boot
 * @Date:   2021-01-20
 * @Version: V1.0
 */
@Api(tags="hy_driver_bill")
@RestController
@RequestMapping("/bill/hyDriverBill")
@Slf4j
public class HyDriverBillController extends JeecgController<HyDriverBill, IHyDriverBillService> {

	 @Autowired
	 private IHyDriverBillService hyDriverBillService;

	 @Resource
	 private IHySettingService settingService;

	/**
	 * 分页列表查询
	 *
	 * @param hyDriverBill
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@ApiOperation(value="hy_driver_bill-分页列表查询", notes="hy_driver_bill-分页列表查询")
	@GetMapping(value = "/list")
	public Result<?> queryPageList(HyDriverBill hyDriverBill,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<HyDriverBill> queryWrapper = QueryGenerator.initQueryWrapper(hyDriverBill, req.getParameterMap());
		Page<HyDriverBill> page = new Page<HyDriverBill>(pageNo, pageSize);
		IPage<HyDriverBill> pageList = hyDriverBillService.page(page, queryWrapper);
		//如果开启系统脱敏
		String dataMaskingFlag = this.settingService.getSettingValueByTag("data_masking");
		if("1".equals(dataMaskingFlag)) {
			for (HyDriverBill dto : pageList.getRecords()) {
				dto.setBillNum(DataMaskingUtil.bankNumberMasking(dto.getBillNum()));
				dto.setCraccno(DataMaskingUtil.bankNumberMasking(dto.getCraccno()));
				dto.setDbaccno(DataMaskingUtil.bankNumberMasking(dto.getDbaccno()));
			}
		}

		return Result.OK(pageList);
	}

//	/**
//	 *   添加
//	 *
//	 * @param hyDriverBill
//	 * @return
//	 */
//	@AutoLog(value = "hy_driver_bill-添加")
//	@ApiOperation(value="hy_driver_bill-添加", notes="hy_driver_bill-添加")
//	@PostMapping(value = "/add")
//	public Result<?> add(@RequestBody HyDriverBill hyDriverBill) {
//		hyDriverBillService.save(hyDriverBill);
//		return Result.OK("添加成功！");
//	}
//
//	/**
//	 *  编辑
//	 *
//	 * @param hyDriverBill
//	 * @return
//	 */
//	@AutoLog(value = "hy_driver_bill-编辑")
//	@ApiOperation(value="hy_driver_bill-编辑", notes="hy_driver_bill-编辑")
//	@PutMapping(value = "/edit")
//	public Result<?> edit(@RequestBody HyDriverBill hyDriverBill) {
//		hyDriverBillService.updateById(hyDriverBill);
//		return Result.OK("编辑成功!");
//	}
//
//	/**
//	 *   通过id删除
//	 *
//	 * @param id
//	 * @return
//	 */
//	@AutoLog(value = "hy_driver_bill-通过id删除")
//	@ApiOperation(value="hy_driver_bill-通过id删除", notes="hy_driver_bill-通过id删除")
//	@DeleteMapping(value = "/delete")
//	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
//		hyDriverBillService.removeById(id);
//		return Result.OK("删除成功!");
//	}
//
//	/**
//	 *  批量删除
//	 *
//	 * @param ids
//	 * @return
//	 */
//	@AutoLog(value = "hy_driver_bill-批量删除")
//	@ApiOperation(value="hy_driver_bill-批量删除", notes="hy_driver_bill-批量删除")
//	@DeleteMapping(value = "/deleteBatch")
//	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
//		this.hyDriverBillService.removeByIds(Arrays.asList(ids.split(",")));
//		return Result.OK("批量删除成功!");
//	}
//
//	/**
//	 * 通过id查询
//	 *
//	 * @param id
//	 * @return
//	 */
//	@AutoLog(value = "hy_driver_bill-通过id查询")
//	@ApiOperation(value="hy_driver_bill-通过id查询", notes="hy_driver_bill-通过id查询")
//	@GetMapping(value = "/queryById")
//	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
//		HyDriverBill hyDriverBill = hyDriverBillService.getById(id);
//		if(hyDriverBill==null) {
//			return Result.error("未找到对应数据");
//		}
//		return Result.OK(hyDriverBill);
//	}
//
    /**
    * 导出excel
    *
    * @param request
    * @param hyDriverBill
    */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, HyDriverBill hyDriverBill) {
        return super.exportXls(request, hyDriverBill, HyDriverBill.class, "司机提现流水单");
    }
//
//    /**
//      * 通过excel导入数据
//    *
//    * @param request
//    * @param response
//    * @return
//    */
//    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
//    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
//        return super.importExcel(request, response, HyDriverBill.class);
//    }

}
